package maa.dao;

import maa.entity.Client;
import maa.entity.Gender;
import maa.entity.User;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

public class UserDAO extends DAO {
    private static UserDAO instance;
    private static List<User> users = new ArrayList<>();

    {
        User user = new Client("x", "1","Luka","Giorgadze",Date.valueOf("1994-09-20"), Gender.MALE);
        users.add(user);
    }

    public static UserDAO getInstance(){
        if (instance == null){
            instance = new UserDAO();
        }
        return instance;
    }

    public User find(String email, String password) {
        for (User user : users) {
            if (user.getEmail().equals(email) && user.getPassword().equals(password)) return user;
            else return null;
        }
        return null;
    }

    public User createUser(String email, String password, String name, String surname, Date birthdate, Gender gender){
        User user = new Client(email,password,name,surname,birthdate,gender);
        return user;
    }

    public void addUser(User user){
        users.add(user);
    }
}
